package com.meta.func.control;

import com.meta.func.bo.CreateFilterParam;
import com.meta.func.service.FilterFuncService;
import com.meta.nd.vo.Nv;
import com.meta.nd.vo.RequestMessage;
import com.meta.nd.vo.ReturnMessage;
import com.meta.util.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@Slf4j
@RestController
public class FuncController {

	@Resource
	FilterFuncService filterFuncService;
	@RequestMapping(value="/func/initFilterFuncParam", method = { RequestMethod.POST })
	public ReturnMessage<Nv> initFilterFuncParam(@RequestBody RequestMessage<CreateFilterParam> requestMessage ) {
		CreateFilterParam param = requestMessage.getValue();
		String targetNdCode = param.getNdCode();
		String returnNdCode = param.getReturnNdCode();
		String postfix = param.getPostfix();
		try {
			Nv initFilterParam = this.filterFuncService.initFilterFuncParamNv(targetNdCode,returnNdCode,postfix);
			return new ReturnMessage<Nv>(true,null,initFilterParam);
		} catch (Exception e ) {
			log.error(e.getMessage(),e);
			return ExceptionUtils.buildReturnMessage(e);
		}
	}

	@RequestMapping(value="/func/commitFilterFunc", method = { RequestMethod.POST })
	public ReturnMessage<Nv> commitFilterFunc(@RequestBody RequestMessage<Nv> requestMessage ) {
		Nv paramNv = requestMessage.getValue();
		try {
			Nv filterDefNv = this.filterFuncService.commitFilterFuncNv(paramNv);
			return new ReturnMessage<Nv>(true,null,filterDefNv);
		} catch (Exception e ) {
			log.error(e.getMessage(),e);
			return ExceptionUtils.buildReturnMessage(e);
		}
	}

}


